
package com.compuvest.webstatus;

// <editor-fold defaultstate="collapsed" desc="import">
import java.util.HashMap;
import java.util.Iterator;
// </editor-fold>

public class StatMap<K,V> extends HashMap {

// <editor-fold defaultstate="collapsed" desc="global">
    public final static String ACTIVE               = "active";

    public final static String TODAY_NEW_CUSTOMER   = "todayNewCust";
    public final static String TODAY_OLD_CUSTOMER   = "todayOldCust";
    public final static String TODAY_VISIT          = "todayVisit";
    public final static String TODAY_ORDERS         = "todayOrder";

    public final static String TOTAL_CUSTOMER       = "totalCust";
    public final static String TOTAL_VISIT          = "totalVisit";
    public final static String TOTAL_ORDERS         = "totalOrder";

    public final static String NOT_FILLED_FORM      = "notFillForm";
    public final static String YES_FILLED_FORM      = "yesFillForm";

    public final static String RESELLER             = "Reseller";

    public final static String VISITS = "_v";
    public final static String ORDERS = "_o";
    public final static String AMOUNT = "_a";
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="init()">

    public void init(String name) {
        this.init(name, 0);
    }

    public void init(String name, int value) {
        super.put(name, new Integer(value));
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="increase()">
    /**
     * Constructs <tt>increase + 1</tt> if found
     * overwise set 1
     *
     * @param  name -
     */
    public void increase(String name) {
//        addValue(name, 1);
        super.put(name, super.containsKey(name) ? (Integer)super.get(name) + 1 : new Integer(1));
    }

// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="decrease()">
    /**
     * Constructs <tt>decrease - 1</tt> if found
     * overwise set 0
     *
     * @param  name -
     */
    public void decrease(String name) {
        super.put(name, super.containsKey(name) ? (Integer)super.get(name) - 1 : new Integer(0));
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="addValue()">
    /**
     * Constructs <tt>add value + value</tt> if found
     * overwise set 0
     *
     * @param  name -
     */
    public void addValue(String name, int value) {
        super.put(name, super.containsKey(name) ? (Integer)super.get(name) + value : new Integer(value));
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="getJSON()">
//----------------------------------
//
    public String getJSON() {

        StringBuilder json = new StringBuilder();
        String name;

        json.append("{inf:{");
        Iterator enter = super.keySet().iterator();
        for(int idx = 0; enter.hasNext(); idx++) {
            name = (String)enter.next();
            if(idx != 0) { json.append(','); }
            json.append("\'").append(name).append("\':").append(super.get(name));
        }
        json.append("}}");

        return json.toString();
    }
// </editor-fold>

}
